var loading = '<img src="/mcs/modpub/images/loading_small.gif"/>';

function byID(id){
    return document.getElementById(id);
}

function show_tool(obj_name){
    var objName = byID(obj_name);

    if(objName.style.display == "none"){
      objName.style.display = "block";
      objName.style.visibility  = "visible";
    } else {
      objName.style.display = "none";
    }

}

function hide_t(ob1,ob2){
   byID(ob1).style.display = "none";
   if (byID(ob2)) { byID(ob2).style.display = "block"; }
}

function Json_eval(edata){
    try 
    {
        return Json.evaluate(edata);
    } 
    catch(err) 
    {
        //err.description
        //document.location.reload()
		$('mymsg').innerHTML = err.stack
		
    }

}

function note(message)
{
    if (message) alert(message); 
}

function mytable(data,head,extra)
{
    var myhtml = "<table class='adminlist'><thead><tr>";
    head.each(function(item,h){
        myhtml += "<th><a href=\"javascript: sort('"+item[0]+"')\" >"+item[1]+"</a></th>";
    })
    if (extra[0][0]) myhtml += "<th></th>";
    if (extra[1][0]) myhtml += "<th></th>";

    myhtml += "</tr></thead><tbody>"
    var cls  = ""   

    data.each(function(val,idx){
        cls = (idx%2 == 0) ? "" : "odd";
        e  = " onMouseOver=\"\" "
        e += " onMouseOut=\"\" class='"+cls+"' "
          myhtml += "<tr " + e + " >";
          head.each(function(con){
            myhtml += "<td>"+val[con[0]] +"</td>";
          })

        if (extra[0][0]) myhtml += '<td><a href="#" onclick="'+extra[0][2]+'('+val[extra[0][1]]+');"><img src="modpub/images/tick.png" alt="edit" border="0"></a></td>';
        if (extra[1][0]) myhtml += '<td><a href="#" onclick="'+extra[1][2]+'('+val[extra[1][1]]+');"><img src="modpub/images/publish_x.png" alt="Delete" ></a></td>';
          myhtml += "</tr>";
    }
    )
    myhtml += "</tbody></table>";
    return myhtml;
}

function ClearOptions(OptionList) {
   for (x = OptionList.length; x >= 0; x--) {
      OptionList[x] = null;
   }
}

function AddToOptionList(data,OptionList, OptionValue, OptionText) {
   ClearOptions(OptionList)
   data.each(function(val){
     OptionList[OptionList.length] = new Option(val[OptionText], val[OptionValue]);
   }
   )
}

function optionSelected(m1,id) {
   for (i=0; i<m1.length; i++) {
      if (m1[i].value == id) m1.options[i].selected = true;
   } 
    
}

function optionText(m1){
   for (i=0; i<m1.length; i++) {
      if (m1.options[i].selected == true) return m1.options[i].text;
   } 
}

